﻿#include "stdafx.h"
#include "GrayscaleTask.h"
#include <QVBoxLayout>
#include <QPushButton>
#include <QLabel>


void GrayscaleTask::execute(cv::Mat& image) {
	// 执行灰度化操作
	if (image.channels() == 3) {
		cv::cvtColor(image, image, cv::COLOR_BGR2GRAY);
	}
	else if (image.channels() == 4) {
		cv::cvtColor(image, image, cv::COLOR_BGRA2GRAY);
	}
	else {
		// 如果已经是灰度图，保持不变
	}
}

std::string GrayscaleTask::getName() const {
	return "灰度化";
}

std::unique_ptr<QDialog> GrayscaleTask::getConfigUI() {
	// 创建配置对话框
	auto dialog = std::make_unique<QDialog>();
	QVBoxLayout* layout = new QVBoxLayout(dialog.get());

	// 添加说明标签
	layout->addWidget(new QLabel("灰度化任务：将图像转换为灰度图。"));

	// 添加确认按钮
	QPushButton* okButton = new QPushButton("确认");
	layout->addWidget(okButton);

	// 连接信号：点击确认后关闭对话框
	QObject::connect(okButton, &QPushButton::clicked, dialog.get(), &QDialog::accept);

	return dialog;
}